package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.equipment.domain.req.device.PointCheckStandardManagementPageReq;
import com.ruibang.glass.equipment.entity.device.PointCheckStandardManagement;
import com.ruibang.glass.equipment.mapper.device.PointCheckStandardManagementMapper;
import com.ruibang.glass.equipment.service.PointCheckStandardManagementService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.seata.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * <p>
 * 点检标准服务类
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */

@Slf4j
@Service
public class PointCheckStandardManagementServiceImpl extends ServiceImpl<PointCheckStandardManagementMapper, PointCheckStandardManagement> implements PointCheckStandardManagementService {

    /**
     * 点检标准
     * @param point
     * @return
     */
    @Override
    public IPage<PointCheckStandardManagement> getPointCheckStandardManagementList(PointCheckStandardManagementPageReq point) {
        return baseMapper.getCheckList(new Page<PointCheckStandardManagement>(point.getPageNo(), point.getPageSize()), point);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody addOrUpdateCheck(PointCheckStandardManagement point) {
        if (StringUtils.isBlank(point.getId())){
            baseMapper.insert(point);
            return ResultBody.success();
        }
        baseMapper.updateById(point);
        return ResultBody.success();
    }
}
